<?php
/**
 * User: Jerry
 * Date: 2017/9/23
 * Time: 10:12
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class CollectGoodsModel
 * @author Jerry
 * @package SDXApi\Model
 */
class CollectGoodsModel extends Model
{
    /**
     * @var string
     */
    protected $tableName = 'collect_goods';

    /**
     * @author Jerry
     * @param int $userId
     * @param int $wid
     * @return mixed
     */
    public function findCollectGoodsByUserId($userId = 0, $wid = 8)
    {
        $where = array(
            'c.user_id'     =>  $userId,
            'g.is_delete'   =>  0,
            'g.original_img'=>	array(
				'NEQ',
				''
			),
        );

        $field = 'c.goods_id, g.goods_name,g.goods_thumb,g.goods_img,g.goods_brief,g.is_presell,g.promote_price,g.promote_start_date,g.promote_end_date,g.goods_number,g.warn_number,g.original_img,g.is_on_sale,g.promote_goods_number,g.promote_today_number,g.is_buynow,g.spec_unit,g.spec_value,g.min_buy_num,g.delivery_type,g.delivery_cycle,g.promote_user_rank, gs.practical_num';
        $join = "left join sdx_goods as g on c.goods_id = g.goods_id";

        return $this->alias('c')
                    ->field($field)
                    ->join($join)
                    ->join('LEFT JOIN __GOODS_STORAGE__ AS gs ON g.goods_id = gs.goods_id AND gs.wid = ' . $wid)
                    ->where($where)
                    ->group('c.goods_id')
                    ->select();
    }
}